package main

import "fmt"

func ChangeSlice(slice []int) {
	slice[0] = -99
	//修改形参会影响到函数外的实参
}
func TestSlicePara() {
	var slice []int = []int{1, 2, 3}
	ChangeSlice(slice)
	fmt.Println(slice) //输出[-99, 2, 3]
}

func AnonymousFunc() {
	// f保存了匿名函数
	f := func(data int) {
		fmt.Println("hello", data)
	}
	f(100)
	//或者直接运行一个匿名函数
	func(data int) {
		fmt.Println("hello", data)
	}(200)
}

func CallBack(list []int, f func(int)) {
	for _, v := range list {
		f(v)
	}
}
